<template>
	<el-container>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="list.apiObj" row-key="id" stripe>
				<el-table-column label="通道名字" prop="payment_name" width="150"></el-table-column>
				<el-table-column label="支付方式" prop="type" width="150">
					<template #default="scope">
						<p >{{types[scope.row.type]}}</p>
					</template>
				</el-table-column>
				<el-table-column label="状态" prop="status" width="50">
					<template #default="scope">
						<p >{{scope.row.status == 1 ? '启用' : '禁用'}}</p>
					</template>
				</el-table-column>
				<el-table-column label="排序" prop="sort" width="150"></el-table-column>
				<el-table-column label="创建时间" prop="create_time" width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="100">
					<template #default="scope">
						<el-button type="primary" plain size="small" @click="table_edit(scope.row)">编辑</el-button>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>


</template>

<script>
	import saveDialog from './save'

	export default {
		name: 'configureList',
		components: {
			saveDialog,
		},
		data() {
			return {
				dialog:{
					save: false,
				},
				list: {
					apiObj: this.$API.system.payment.list
				},
				types: {'1': '微信支付', '2': '余额支付', '3': '免押支付', '4': '月卡支付'}
			}
		},
		mounted() {

		},
		methods: {
			//窗口编辑
			table_edit(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('edit').setData(row)
				})
			},

			//本地更新数据
			handleSaveSuccess(data, mode){
				//为了减少网络请求，直接变更表格内存数据
				if(mode=='add'){
					this.$refs.table.unshiftRow(data)
				}else if(mode=='edit'){
					this.$refs.table.updateKey(data)
				}

				//当然也可以暴力的直接刷新表格
				// this.$refs.table.refresh()
			}
		}
	}
</script>

<style>
</style>
